<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="计划单号" prop="reqNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.reqNo" placeholder="请填写计划单号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="申请部门" prop="applyDept"
                :rules="[
                 ]">
              <el-input v-model="inputForm.applyDept" placeholder="请填写申请部门"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="提报人姓名" prop="applyEmp"
                :rules="[
                 ]">
              <el-input v-model="inputForm.applyEmp" placeholder="请填写提报人姓名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物料编码" prop="matrlNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.matrlNo" placeholder="请填写物料编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物料名称" prop="matrlName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.matrlName" placeholder="请填写物料名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="规格型号" prop="nmSepc"
                :rules="[
                 ]">
              <el-input v-model="inputForm.nmSepc" placeholder="请填写规格型号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="计量单位" prop="unit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.unit" placeholder="请填写计量单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="计划申请数量" prop="qty"
                :rules="[
                 ]">
              <el-input v-model="inputForm.qty" placeholder="请填写计划申请数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="计划类型" prop="planType"
                :rules="[
                 ]">
                <el-select v-model="inputForm.planType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('basicdata_part_device_node_hierarchy')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="采购中数量" prop="purQty"
                :rules="[
                 ]">
              <el-input v-model="inputForm.purQty" placeholder="请填写采购中数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="在途数量" prop="onWayQty"
                :rules="[
                 ]">
              <el-input v-model="inputForm.onWayQty" placeholder="请填写在途数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="已接办数量" prop="processQty"
                :rules="[
                 ]">
              <el-input v-model="inputForm.processQty" placeholder="请填写已接办数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="提报日期" prop="applyDate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.applyDate" placeholder="请填写提报日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="审批数量" prop="audiQty"
                :rules="[
                 ]">
              <el-input v-model="inputForm.audiQty" placeholder="请填写审批数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="及时库存" prop="stockQty"
                :rules="[
                 ]">
              <el-input v-model="inputForm.stockQty" placeholder="请填写及时库存"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          reqNo: '',
          applyDept: '',
          applyEmp: '',
          matrlNo: '',
          matrlName: '',
          nmSepc: '',
          unit: '',
          qty: '',
          planType: '',
          purQty: '',
          onWayQty: '',
          processQty: '',
          applyDate: '',
          remarks: '',
          audiQty: '',
          stockQty: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建报表`
        } else if (method === 'edit') {
          this.title = '修改报表'
        } else if (method === 'view') {
          this.title = '查看报表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/spareparts/material/erpReferPlan/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.erpReferPlan)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/spareparts/material/erpReferPlan/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>